package com.fz.song.service.impl;


import com.fz.song.dao.BlogTypeMapper;
import com.fz.song.pojo.BlogInfo;
import com.fz.song.pojo.BlogType;
import com.fz.song.service.IBlogTypeService;
import com.fz.song.util.ResultObj;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogTypeServiceImpl implements IBlogTypeService {

    @Autowired
    private BlogTypeMapper blogTypeMapper;

    private static Log logger = LogFactory.getLog(BlogTypeServiceImpl.class);


    @Override
    public PageInfo<BlogType> getBlogTypeListData(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<BlogType> userList = blogTypeMapper.getBlogTypeListData();
        PageInfo<BlogType> pageInfo = new PageInfo<BlogType>(userList);
        return pageInfo;
    }

    @Override
    public BlogType getBlogTypeByid(String id) {
        return blogTypeMapper.selectByPrimaryKey(id);
    }

    @Override
    public ResultObj saveBlogType(BlogType blogType) {
        int i = blogTypeMapper.insertSelective(blogType);
        if (i == 1) {
            return ResultObj.ok("保存成功");
        }
        return ResultObj.error("保存失败");

    }

    @Override
    public ResultObj updateBlogType(BlogType blogType) {
        int i = blogTypeMapper.updateByPrimaryKeySelective(blogType);
        if (i == 1) {
            return ResultObj.ok("修改成功");
        }
        return ResultObj.error("修改失败");
    }

    @Override
    public ResultObj delBlogType(String id) {
        BlogType blogType = blogTypeMapper.selectByPrimaryKey(id);
        blogType.setDel(1);
        int i = blogTypeMapper.updateByPrimaryKeySelective(blogType);
        if (i == 1) {
            return ResultObj.ok("删除成功");
        }
        return ResultObj.error("删除成功");
    }

    @Override
    public List<BlogType> getBlogTypeList() {
        List<BlogType> blogTypeListData = blogTypeMapper.getBlogTypeListData();
        return blogTypeListData;
    }
}
